package boot.util;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
@Component
public class uploadImgUtil {
    @Resource
    private FastDFSClientUtil fileDfsUtil;

    public String uploadFile(MultipartFile file) throws Exception{
        String result;
        try {
            String path = fileDfsUtil.upload(file);
            if (!StringUtils.isEmpty(path)) {
                result = path;
            } else {
                throw new Exception();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception();
        }
        result = "http://43.140.193.162:6060/" + result;
        return result;
    }
}
